var blockUi = new BlockUi();
var blockUiSet = function(){ 
	var opts = new Array();
	opts["bgcolor"] = "gray";//string
	opts["opacity"] = 0.2;//number
	opts["animation"] = true;//boolean
	
	blockUi.block(opts); 
};
var blockUiUnset = function(){ blockUi.unblock(); };

var errorAjax = function(xhr, status, thrown){
	var code = xhr.status;
	var codeDesc = "";
	if(code == 12029){ codeDesc = "원격 서버 접속 불가능.";
	}else if(code == 500){ codeDesc = "요청 페이지의 내부적인 장애.";
	}else if(code == 404){ codeDesc = "찾을 수 없는 페이지 장애.";
	}else{ codeDesc = code + "(알수 없는 에러.)"; }

	blockUi.hideAnimation();
	alert(codeDesc);// +" : "+ xhr.getResponseHeader("errorMsg") +" : "+ thrown
};

var completeAjax = function(xhr, status){ 
	blockUiUnset();
};

//All (including JSON)
var callAjax = function(option){
	var type = !option.type ? "POST" : option.type;
	$.ajax({
		type:type
		,url:option.url
		,dataType:option.dataType
		,data:option.data
		,beforeSend:function(xhr){
			if(option.contentType != null) {
				xhr.setRequestHeader("Content-Type", option.contentType);
			}
			
			blockUiSet();
		}
		,success:option.success
		,complete:(option.complete != null) ? option.complete : completeAjax
		,error:(option.error != null) ? option.error : errorAjax
	});
};

//JSONP only
var callAjaxJsonP = function(option){
	var type = !option.type ? "POST" : option.type;
	$.ajax({
		type:type
		,url:option.url
		,contentType : option.contentType
		,dataType:option.dataType
		,jsonp:"callback"//JSONP's options. you can change another one.
		,data:option.data
		,beforeSend:function(xhr){
			//JSONP's options. you can change another one.
			xhr.setRequestHeader("Accept", "javascript/jsonp");

			blockUiSet();
		}
		,success:option.success
		,complete:(option.complete != null) ? option.complete : completeAjax
		,error:(option.error != null) ? option.error : errorAjax
	});
};

//Open source
var loadAjaxOpenApi = function(option){
	var type = !option.type ? "POST" : option.type;
	$.ajax({
		type:type
		,cache:option.cache
		,url:option.url
		,contentType : option.contentType
		,dataType:option.dataType
		,data:option.data
		,beforeSend:function(xhr){
			blockUiSet();
		}
		,success:option.success
		,complete:(option.complete != null) ? option.complete : completeAjax
		,error:(option.error != null) ? option.error : errorAjax
	});
};